package com.kaoshi.myweb.web.support.tld;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.kaoshi.myweb.web.entity.User;

public class UserInfoTag extends TagSupport  {
	private User user;

	@Override
	public int doStartTag() throws JspException {
		try {
			JspWriter out = this.pageContext.getOut();
			
			if(getUser() == null){
				out.println("no userinfo");
				return SKIP_BODY;
			}
			
			out.println("<table width='500px' border='1' align='center'>");

            out.println("<tr>");

            out.println("<td width='20%'>Username:</td>");

            out.println("<td>" + getUser().getUsername() + "</td>");

            out.println("</tr>");

            out.println("<tr>");

            out.println("<td>Age:</td>");

            out.println("<td>" + getUser().getLoginName() + "</td>");

            out.println("</tr>");

            out.println("<tr>");

            out.println("<td>Email:</td>");

            out.println("<td>" + getUser().getEmail() + "</td>");

            out.println("</tr>");

            out.println("</table>");
			
		} catch (Exception e) {
			// TODO: handle exception
			throw new JspException(e.getMessage());
		}
		
		
		return SKIP_BODY;
	}
	

	@Override
	public int doEndTag() throws JspException {
		// TODO Auto-generated method stub
		return super.doEndTag();
	}

	@Override
	public void release() {
		// TODO Auto-generated method stub
		super.release();
		this.user = null;
	}
	
	public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}
	
	
}
